package com.pan.studentmaster;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class Main extends Activity implements View.OnTouchListener {
	
	static public String APP_NAME = "StudentMaster";
	
	static public Main instance() {
		return _instance;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if(_instance == null)
			_instance = this;
		new Initializer();
		Student s = Student.instance();
		setContentView(R.layout.layout_main);
		TextView textSchool = (TextView)findViewById(R.id.textViewSchool);
		textSchool.setText(s.getSchool());
		TextView textClass = (TextView)findViewById(R.id.textViewClass);
		textClass.setText("Class " + s.getGrade() + s.getClassA() + " No." + s.getNumber());
		TextView textName = (TextView)findViewById(R.id.textViewStudent);
		textName.setText(s.getName());
		ImageView iv = (ImageView)findViewById(R.id.imageView1);
		iv.setOnTouchListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu_main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			Intent i = new Intent().setClass(this, Pref.class);
			startActivity(i);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		if(event.getAction() == MotionEvent.ACTION_DOWN) {
			Intent i = new Intent().setClass(this, CourseActivity.class);
			Log.i("MAIN", "start CourseActivity");
			startActivity(i);
		}
		return true;
	}
	
	// private
	
	static private Main	_instance = null;
}
